<template>
  <div id="box">
    <!--未选中-->
    <div class="chat-item" data-chat="public" @click="click(data)"
         v-show="!changeState">
      <span>{{ name }}</span>
      <div class="edit" @click="edit(data.id)">编辑</div>
    </div>

    <!--选中-->
    <div class="chat-item active" data-chat="public" @click="click(data)"
         v-show="changeState">
      <span>{{ name }}</span>
      <!--禁止事件冒泡, 若不禁止, edit事件触发同时会触发click事件-->
      <div class="edit" @click.stop="edit(data.id)">编辑</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ChatItem",
  props: ['changeState', 'name', 'click', 'data', 'edit']
}
</script>

<style scoped>
.chat-item {
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 4px;
  margin-bottom: 10px;
  cursor: pointer;
}

.chat-item.active {
  background-color: #9ca7ea;
}

.edit {
  float: right;
}
</style>